package rdb.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

public class SetObject extends BaseObject {
    private byte[][] members;

    HashMap<String, Boolean> hm;

    public SetObject(BaseObject baseObject, byte[][] val) {
        super(baseObject);
        members = val;
        hm = new HashMap<>();
        for (byte[] m : members) {
            hm.put(new String(m), true);
        }
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("Set: ");
        for (byte[] bs : members) {
            sb.append(new String(bs)).append(" ");
        }
        sb.append("\n");
        return sb.toString();
    }

    @Override
    public Object getValue() {
        return hm;
    }

    @Override
    public String[] getCmdLines() {
        String[] ret = new String[2+members.length];
        int i = 0;
        ret[i++] = "sadd";
        ret[i++] = getKey();
        for (byte[] member : members) {
            ret[i++] = new String(member);
        }
        return ret;
    }
}
